package 测试;

public class 打印二维数组 {

	public static void main(String[] args) {

	}

}

class Printer {
	public int[] arrayPrint(int[][] arr, int n) {
		int[] r = new int[n * n];
		int idx = 0;
		// 分层打印控制变量
		int layerX = 1;
		int layerY = n - 1;
		// 遍历矩阵元素的游标
		int i = 0;
		int j = n - 1;
		// 打印矩阵的上右三角
		while (layerY >= 0) {
			// 设定该层打印的起始点
			i = 0;
			j = layerY;
			while (j < n) {
				r[idx++] = arr[i++][j++];
			}
			layerY--;
		}
		// 打印矩阵的下左三角
		while (layerX <= n - 1) {
			// 设定该层打印的起始点
			i = layerX;
			j = 0;
			while (i < n) {
				r[idx++] = arr[i++][j++];
			}
			layerX++;
		}
		return r;
	}
}